package com.xian.loop;

public class ForDemo2 {
    public static void main(String[] args) {
        //目标:求和

        int sum = 0;
        for (int i=1; i<=5; i++){
            sum += i;
            System.out.println(i);
        }
        System.out.println(sum);

        System.out.println("===============================");

        //求奇数和

        //方法一
        int jSum = 0;
        for (int i = 1; i <= 10; i+=2) {
            jSum += i;
            System.out.println(i);
        }
        System.out.println(jSum);

        //方法二
        int jSum1 = 0;
        for (int i = 1; i <= 10; i++) {
            if(i % 2 == 1){
                jSum1 += i;
            }
        }
        System.out.println(jSum1);

    }
}
